<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<form method="post" action="{$ADMIN_SCRIPT}/user/message/{$dispatches[method]}&do={$_var[gp_do]}&id={$_var[gp_id]}" onsubmit="javascript:return check_form(this);">
			<input type="hidden" name="formsubmit" value="yes" />
			<div class="well widget">
				<div class="widget-header">
					<p class="text">* {lang admin.validate.require}</p>
				</div>
				<div class="widget-content">
				<fieldset>
					<label>{lang user.message_tpl_edit.view.title.label} *</label>
					<!--{if $message_tpl}-->
					{$message_tpl[TITLE]} {$message_tpl[SERIAL]}
					<!--{else}-->
					<!--{loop $message_tpls $loop $tpl}-->
						<!--{if !$message_tpl_added[$tpl['SERIAL']]}-->
						<label class="checkbox">
							<input class="fancy" name="rdoMsgTpl" content="{$tpl[CONTENT]}" remark="{$tpl[REMARK]}" type="radio" value="{$tpl[SERIAL]}" {if $message_tpl['SERIAL'] == $tpl['SERIAL']}checked="checked"{/if}/>{$tpl[TITLE]} {$tpl[SERIAL]}
						</label>
						<!--{/if}-->
					<!--{/loop}-->
					<!--{/if}-->
					
					<hr/>
					<label>{lang user.message_tpl_edit.view.identity.label} *</label>
					<input type="text" class="input-xxlarge" name="txtIdentity" maxlength="50" value="{$message_tpl[IDENTITY]}" placeholder="{lang user.message_tpl_edit.view.identity.placeholder}"/>
					<span class="help-inline">{lang user.message_tpl_edit.view.identity.tips}</span>
					
					<hr/>
					<h5>{lang user.message_tpl_edit.view.content.label}</h5>
					<p class="detail">{$message_tpl[CONTENT]}</p>
					
					<label>{lang user.message_tpl_edit.view.remark.label} *</label>
					<textarea class="span6" rows="4" name="txtRemark" placeholder="{lang user.message_tpl_edit.view.remark.placeholder}">{$message_tpl[REMARK]}</textarea><br/>
					<span class="help-inline">{lang user.message_tpl_edit.view.remark.tips}</span>
					
					<hr/>
					<button type="submit" class="btn btn-small btn-primary">{lang admin.operation.submit}</button>
					<button type="reset" class="btn btn-small btn-reset">{lang admin.operation.reset}</button>
					<button type="button" class="btn btn-small" onclick="javascript:location.href='{$ADMIN_SCRIPT}/user/message/_tpl';">{lang admin.operation.go.back}</button>
				</fieldset>
				</div>
			</div>
			</form>
		</div>
	</div>
</div>

<script>
function check_form(frm){
    if(frm.txtIdentity.value.trim().length == 0){
    	$(frm.txtIdentity).next('.help-inline').css('color', 'red');
    	frm.txtIdentity.focus();
    	return false;
    }
    
    if(frm.txtRemark.value.trim().length == 0){
    	$(frm.txtRemark).next('.help-inline').css('color', 'red');
    	frm.txtRemark.focus();
    	return false;
    }
    
    return true;
}

$(function(){
	$('.fancy').uniform();
	
	$('fieldset input,textarea').blur(function(){
		$(this).next('.help-inline').css('color', '#333');
	});
	
	$("input[name='rdoMsgTpl']").click(function(){
		$('.detail').html($(this).attr('content'));
		var remark = $(this).attr('remark') + '';
		if(remark){
			$("textarea[name='txtRemark']").val(remark.replace(/\\n/g, "\n"));
		}
	});
	
	{if !$message_tpl}
		var radio = $("input[name='rdoMsgTpl']").first();
		$(radio).attr('checked', true).parent().addClass('checked');
		$('.detail').html($(radio).attr('content'));
		
		var remark = $(radio).attr('remark') + '';
		if(remark){
			$("textarea[name='txtRemark']").val(remark.replace(/\\n/g, "\n"));
		}
	{/if}
});
</script>
<!--{template /module/admin/view/foot}-->